/**
 * LongEditor.java
 * Created at 2016年10月22日
 * Created by Jackie Liu
 * Copyright (C) 2016 Jackie Liu, All rights reserved.
 */
package com.huabo.editors;

import com.huabo.utils.ValidateUtils;
import org.apache.commons.lang3.StringUtils;

import java.beans.PropertyEditorSupport;


/**
 * <p>ClassName: LongEditor</p>
 * <p>Description: Long类型属性编辑器</p>
 * <p>Author: Jackie Liu</p>
 * <p>Date: 2016年10月22日</p>
 */
public class LongEditor extends PropertyEditorSupport {

	/* (non-Javadoc)
	 * <p>Title: setValue</p>
	 * <p>Description: </p>
	 * @param value
	 * @see java.beans.PropertyEditorSupport#setValue(java.lang.Object)
	 */
	@Override
	public void setValue(Object value) {
		if (value instanceof Long) {
			super.setValue((Long) value);
		} else {
			super.setValue(value);
		}
	}

	/* (non-Javadoc)
	 * <p>Title: setAsText</p>
	 * <p>Description: </p>
	 * @param text
	 * @throws IllegalArgumentException
	 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
	 */
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		if (StringUtils.isEmpty(text)
				|| !ValidateUtils.validateInteger(text)) {
			this.setValue(0);
			return;
		}
		this.setValue(Long.valueOf(text));
	}
}
